define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'tongcheng/delivery_order_refund/index' + location.search,
                    // add_url: 'tongcheng/delivery_order_refund/add',
                    // edit_url: 'tongcheng/delivery_order_refund/edit',
                    // del_url: 'tongcheng/delivery_order_refund/del',
                    // multi_url: 'tongcheng/delivery_order_refund/multi',
                    // import_url: 'tongcheng/delivery_order_refund/import',
                    table: 'tongcheng_delivery_order_refund',
                }
            });

            var table = $("#table");

            // 在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
              let form = $("form", table.$commonsearch);

              $("input[name='zone_id']", form).addClass("selectpage").data("source", "tongcheng/zone/index").data("params", {"custom[status]": 1}).data("orderBy","id desc");
              $("input[name='user_id']", form).addClass("selectpage").data("source", "user/user/index").data("field", "nickname").data("orderBy","id desc").data("formatItem","{nickname}({id})");

              Form.events.cxselect(form);
              Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                // fixedColumns: true,
                // fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},

                        {field: 'zone_id', title: __('Zone_id'), visible: false},
                        {
                          field: 'zone.name', title: __('Zone.name'), operate: false, formatter: function (value, row, index) {
                            return value + '(' + row.zone_id + ')';
                          }
                        },
                        {field: 'user_id', title: __('User_id'), visible: false},
                        {
                          field: 'user.nickname', title: '用户昵称', operate: false, formatter: function (value, row, index) {
                            return value + '(' + row.user_id + ')';
                          }
                        },
                        {field: 'order_id', title: __('Order_id'), },
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},

                        // {field: 'zone_id', title: __('Zone_id')},
                        // {field: 'order_id', title: __('Order_id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user_role', title: __('User_role'), searchList: {"CUSTOMER":__('CUSTOMER'),"RIDER":__('RIDER'),"ADMIN":__('ADMIN'),"SYSTEM":__('SYSTEM')}, formatter: Table.api.formatter.normal},
                        {field: 'refund_no', title: __('Refund_no'), operate: 'LIKE'},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'refund_fee', title: __('Refund_fee'), operate:'BETWEEN'},
                        {field: 'refund_coupon_id', title: __('Refund_coupon_id')},
                        {field: 'operate_role', title: __('Operate_role'), searchList: {"CUSTOMER":__('CUSTOMER'),"RIDER":__('RIDER'),"ADMIN":__('ADMIN'),"SYSTEM":__('SYSTEM')}, formatter: Table.api.formatter.normal},
                        {field: 'operate_user_id', title: __('Operate_user_id')},
                        {field: 'status', title: __('Status'), searchList: {0:__('Status create'),1:__('Status accept'),2:__('Status reject')}, formatter: Table.api.formatter.status},
                        {field: 'reject_remark', title: __('Reject_remark'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'zone.name', title: __('Zone.name'), operate: 'LIKE'},
                        // {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        // {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'coupon.name', title: __('Coupon.name'), operate: 'LIKE'},

                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
